# -*- coding: utf-8 -*-
# Author: xiantingDeng
# Email: dengxianting@shxgroup.net
# Time: 15:51


from common.utils.file_util import get_app_dir
from common.utils.read_util import OperationIni
from common.utils.file_util import get_real_ini_dir


class EnvionMent():
    def __init__(self):
        self.data_path = get_real_ini_dir("env.ini")
        self.env = OperationIni(self.data_path).get_ini_file_path_section_data("environment")

    def get_env_data(self):
        '''
        获取当前运行环境 真：prod  假：test
        :return: 真或假
        '''
        try:
            if self.env.get("current_env") == "prod":
                return True
            elif self.env.get("current_env") == "test":
                return False
            else:
                print("运行环境选择错误，请检查env.ini配置文件是否正常")
        except Exception as e:
            raise "环境选择错误：{}".format(e)

    def get_package_path(self):
        '''
        根据当前运行环境判断使用哪个安装包
        :return: 返回安装包路径
        '''
        if self.get_env_data():
            package_path = get_app_dir("JinDi_0405_ali.apk")
        else:
            package_path = get_app_dir("JinDi_0405_ali.apk")
        return package_path

    def operating_environment(self):
        if self.get_env_data():
            return "生产环境"
        else:
            return "测试环境"
